package com.lemon.smartsafety.ui.activity.common;

import android.os.Bundle;

import com.lemon.smartsafety.app.AppService;
import com.lemon.smartsafety.app.BundleKey;
import com.lemon.smartsafety.app.EventTag;
import com.lemon.smartsafety.entity.common.AreaVo;
import com.lemon.smartsafety.entity.event.common.AreaSelectEvent;
import com.lemon.smartsafety.http.service.CommonServices;
import com.lemon.smartsafety.listener.AreaType;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.utils.app.UIHelper;

/**
 * Created by Cooliean on 16/4/6.
 */
public class AreaProvinceActivity extends AreaBaseActivity implements RecyclerTClickListener<AreaVo> {

    private boolean isRegister = false;

    @Override
    protected void getBundleArgs() {
        super.getBundleArgs();
        if (getIntent().getExtras() != null) {
            isRegister = getIntent().getExtras().getBoolean(BundleKey.IS_FOR_REGISTER, false);
        }
    }

    @Override
    public String getTag() {
        return EventTag.TAG_AREA_PROVINCE;
    }

    @Override
    public void getNetData() {
        CommonServices.init().getProvinceInfo();
    }

    @Override
    protected void initTitle() {
        setBarTitle("省份");
    }

    @Override
    public void onItemClick(AreaVo data, int position) {
        AreaSelectEvent event = new AreaSelectEvent();
        event.setTag(AreaSelectEvent.class.getName());
        event.setData(data);
        event.setType(AreaType.PROVINCE);
        AppService.getBus().post(event);


        if (!data.isHasChild()) {
            callFinish();
        } else {
            Bundle bundle = new Bundle();
            bundle.putBoolean(BundleKey.IS_FOR_REGISTER, isRegister);
            bundle.putString(BundleKey.AREA_PARENT_ID, data.getVoId());
            bundle.putString(BundleKey.AREA_PARENT_TITLE, data.getTitle());
            UIHelper.showActivity(this, bundle, AreaCityActivity.class);
        }
    }

}
